package com.gx.ring.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.gx.ring.dao.RingExistCorpIDInterfaceDAO;
import com.gx.ring.entity.FailregLog;

public class FLInterfaceImplDAO implements RingExistCorpIDInterfaceDAO<FailregLog>{
	private Connection conn = null;
	
	public FLInterfaceImplDAO(Connection conn) {
		this.conn = conn;
	}
	@Override
	public List<FailregLog> queryByphNumber(String phNumber) throws SQLException {
		String sql = "SELECT * FROM ring.t_failreglog WHERE PHONENUMBER=?  ";
		List<FailregLog> ls = new ArrayList<>();
		FailregLog fl = new FailregLog();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, phNumber);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			fl = saveResult(rs);
			ls.add(fl);
		}
		rs.close();
		pst.close();
		return ls;
	}
	
	@Override
	public List<FailregLog> queryByCorpCode(String corpCode) throws SQLException {
		String sql = "SELECT * FROM ring.t_failreglog WHERE CORPCODE=?  ";
		List<FailregLog> ls = new ArrayList<>();
		FailregLog fl = new FailregLog();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, corpCode);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			fl = saveResult(rs);
			ls.add(fl);
		}
		rs.close();
		pst.close();
		return ls;
	}
	
	@Override
	public FailregLog saveResult(ResultSet rs) throws SQLException {
		FailregLog fl = new FailregLog();
		fl.setLogid(rs.getLong("LOGID"));
		fl.setLogtime(rs.getTimestamp("LOGTIME"));
		fl.setOperatetype(rs.getLong("OPERATETYPE"));
		fl.setCorpcode(rs.getString("CORPCODE"));
		fl.setPhonenumber(rs.getString("PHONENUMBER"));
		fl.setResultcode(rs.getString("RESULTCODE"));
		fl.setBosserturncode(rs.getString("BOSSRETURNCODE"));
		fl.setOperatortype(rs.getLong("OPERATORTYPE"));
		fl.setOperatorcode(rs.getString("OPERATORCODE"));
		fl.setOperator(rs.getLong("OPERATOR"));
		fl.setDescription(rs.getString("DESCRIPTION"));
		fl.setUsdpip(rs.getString("USDPIP"));
		fl.setOutreturncode(rs.getString("OUTRETURNCODE"));
		return fl;
	}

}
